package com.example.test.dialog

import android.content.Context
import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        btn1.setOnClickListener {
            val myDialog = AlertDialog.getInstance(this, R.style.tran_dialog)
            myDialog.setLoadingText( "正在加载中...")
            myDialog.loadDialog(true)
                    .isCancelable(true)
                    .setDuration(500)
                    .isOpen(true)
            myDialog.show()
        }
        btn2.setOnClickListener {
            val myDialog = AlertDialog.getInstance(this, R.style.tran_dialog)
            myDialog.setTitle("What are you do in?")
                    .setMessage("I'm knocking the code")
                    .setDuration(500)
                    .isCancelable(false)//禁止點擊背景
                    .isOpen(true)
                    .setNegativeButton("跳转", object : AlertDialog.OnClickListener {
                        override fun onClick(dialog: AlertDialog?, which: Int) {
                            myDialog.isOpen(false)//跳转时可以关闭动画，退出动画将不再出现
                            startActivity(Intent(this@MainActivity, MainActivity::class.java))
                            dialog!!.dismiss()
                        }
                    })
                    .setPositiveButton("取消", object : AlertDialog.OnClickListener {
                        override fun onClick(dialog: AlertDialog?, which: Int) {
                            dialog!!.dismiss()
                        }
                    })
                    .setNeutralButton("忽略", object : AlertDialog.OnClickListener {
                        override fun onClick(dialog: AlertDialog?, which: Int) {
                            dialog!!.dismiss()
                        }
                    }).show()

        }
    }

}
